package pyf.demo11;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author pengyifeng
 * @version 5.1
 * @ClassName TestJUCDemo.java
 * @Description 线程安全的集合
 * @createTime 2021年07月27日 11:54:00
 */
public class TestJUCDemo {
    public static void main(String[] args) {
        CopyOnWriteArrayList<String> list=new CopyOnWriteArrayList<>();
        for (int i = 0; i < 9999; i++) {
            new Thread(()->list.add(Thread.currentThread().getName())).start();
        }
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(list.size());
    }
}
